package com.iro.blog.web;

import com.iro.blog.Service.BlogsService;
import com.iro.blog.Service.TagService;
import com.iro.blog.Service.TypeService;
import com.iro.blog.pojo.Tag;
import com.iro.blog.pojo.Type;
import com.iro.blog.vo.BlogQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TagShowController {
    @Autowired
    private TagService tagService;

    @Autowired
    private BlogsService blogsService;

    @GetMapping("/tags/{id}")
    public String Tags(Model model, @PageableDefault(size = 3,sort = {"updateTime"},direction = Sort.Direction.DESC) Pageable pageable, @PathVariable Long id){
        List<Tag> tags=tagService.listTagTop(10000);
        if (id==-1){
            id=tags.get(0).getId();
        }
        model.addAttribute("tags",tags);
        model.addAttribute("page",blogsService.listBlog(id,pageable));
        model.addAttribute("activeTagId",id);
        model.addAttribute("recommendBlogs",blogsService.listRecommendBlogTop(1));
        return "tags";
    }
}
